import requests
from user_agent_get import userAgentGet
from pyquery import PyQuery

url='https://www.qidian.com/rank/yuepiao/'
headers={'user-Agent':userAgentGet('firefox').userAgentGetValue()}

respon=requests.get(url,headers=headers)

mypy=PyQuery(respon.text)
author_q=mypy(".book-mid-info").items()

with open("code1/test2.txt",'w',encoding='utf-8') as f:
    for i in author_q:
        str1=""+"-------------------\n"
        str1=str1+"小说题目："+i("h4").text()+"\n"
        str1=str1+"作者："+i(".name").text()+"\n"
        str1=str1+"小说类型："+i("a[data-eid='qd_C42']").text()+"\n"
        str1=str1+"小说总体描述："+i(".intro").text()+"\n-------------------------\n"
        f.write(str1)

# with open('code1/test2.html','r',encoding='utf-8') as f:
#     htmlStr=f.read()


# # print(htmlStr)
# mypy=PyQuery(htmlStr)
# author_q=mypy(".book-mid-info").items()
# for i in author_q:
#     print(i.html())
#     print('--------------')
#     print("小说题目："+i("h4").text())
#     print("作者："+i(".name").text())
#     print("小说类型："+i("a[data-eid='qd_C42']").text())
#     print("小说总体描述："+i(".intro").text())
#     break